-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alexander Anronov @raccoon6996 #237
base: master
Are you sure you want to change the base?
Conversation
[Test] | ||
public void NumberValidator_WithNegativePrecision_ThrowsArgumentException() | ||
{ | ||
Assert.Throws<ArgumentException>(() => new NumberValidator(-1, 2, true)); | ||
} | ||
|
||
[Test] | ||
public void NumberValidator_WithNegativeScale_ThrowsArgumentException() | ||
{ | ||
Assert.Throws<ArgumentException>(() => new NumberValidator(2, -2, true)); | ||
} | ||
|
||
[Test] | ||
public void NumberValidator_WithScaleGreaterThanPrecision_ThrowsArgumentException() | ||
{ | ||
Assert.Throws<ArgumentException>(() => new NumberValidator(2, 4, true)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше использовать TestCase, кстати, каждому кейсу можно задать свое имя с помощью TestName
[TestCase("1.0.1")] | ||
public void IsValidNumber_WithIncorrectValue_ReturnFalse(string value) | ||
{ | ||
Assert.False(new NumberValidator(10, 5).IsValidNumber(value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Читается тяжело, можно разделить на инициализацию, вызов метода и проверку значения
|
||
Assert.False(validator.IsValidNumber(value)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Потерялся атрибут
[TestCase(17, 2, true, "0.0")] | ||
[TestCase(17, 2, true, "0")] | ||
[TestCase(17, 2, true, "+0.0")] | ||
[TestCase(3, 1, true, "+1.2")] | ||
[TestCase(3, 1, false, "-1.2")] | ||
public void IsValidNumber_WithProperValue_Success | ||
(int precision, int scale, bool positive, string value) | ||
{ | ||
var validator = new NumberValidator(precision, scale, positive); | ||
|
||
Assert.True(validator.IsValidNumber(value)); | ||
} | ||
|
||
[TestCase(" ")] | ||
[TestCase("")] | ||
[TestCase(null)] | ||
[TestCase("+-1")] | ||
[TestCase("abc")] | ||
[TestCase("a.bc")] | ||
[TestCase("1.0.1")] | ||
public void IsValidNumber_WithIncorrectValue_ReturnFalse(string value) | ||
{ | ||
Assert.False(new NumberValidator(10, 5).IsValidNumber(value)); | ||
} | ||
|
||
|
||
[TestCase("-1.0")] | ||
[TestCase("+1.0")] | ||
[TestCase("10.0")] | ||
[TestCase("1.00")] | ||
public void IsValidNumber_WithValueGreaterThanPrecision_ReturnFalse(string value) | ||
{ | ||
var validator = new NumberValidator(2, 1); | ||
|
||
Assert.False(validator.IsValidNumber(value)); | ||
} | ||
|
||
[TestCase(true, "1.00")] | ||
[TestCase(false, "-1.00")] | ||
public void IsValidNumber_WithFracPartGreaterThanScale_ReturnFalse(bool positive, string value) | ||
{ | ||
var validator = new NumberValidator(10, 1, positive); | ||
|
||
Assert.False(validator.IsValidNumber(value)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Честно говоря тут тоже ничего не мешает переделать все на тест кейсы
} | ||
} | ||
|
||
public class NumberValidator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вынести в отдельный файл. На шпоре, имхо, важно не только смотреть на то место, куда ты вносишь изменения но и на весь проект в целом, если видишь что где-то сделано не очень хорошо - исправляй. Так работает и в промышленной разработке (за исключением случаев, когда код написан настолько плохо, что трогать его страшно)
No description provided.